<?php

namespace App\Http\Controllers\Api;


use App\Exceptions\ResourceNotFoundException;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class BoardController extends Controller
{
    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function create(Request $request)
    {
        $user = $request->user();
        $title = $request->get('title');
        $userId = $user->id;
        $board = $this->boardService->createBoard($title, $userId);
        return $this->success($board);
    }

    /**
     * @param Request $request
     * @param null $boardId
     * @return \Illuminate\Http\JsonResponse
     */
    public function get(Request $request, $boardId = null)
    {
        $user = $request->user();
        return $this->success($this->boardService->getBoard($user->id, $boardId));
    }

    /**
     * @param Request $request
     * @param int $boardId
     * @return \Illuminate\Http\JsonResponse
     */
    public function getAll(Request $request, int $boardId)
    {
        $user = $request->user();
        return $this->success($this->boardService->getBoard($user->id, $boardId));
    }


    /**
     *
     */
    public function archive()
    {

    }

    /**
     * @param Request $request
     * @param $boardId
     * @return bool|null
     * @throws ResourceNotFoundException
     */
    public function delete(Request $request, $boardId)
    {
        $this->success($this->boardService->deleteBoard($boardId));
    }


    /**
     * @param Request $request
     * @param $boardId
     * @return mixed
     * @throws ResourceNotFoundException
     */
    public function update(Request $request, $boardId)
    {
        return $this->boardService->updateBoard($boardId, $request->all());
    }

}
